MV_CC_IsDeviceConnected

MV_CC_IsDeviceConnected

Check if device is connected.

API Definition

bool MV_CC_IsDeviceConnected(
  void        *handle
);

Parameters

handle

[IN] Device handle, which is returned by MV_CC_CreateHandle or MV_CC_CreateHandleWithoutLog.

Return Value

Return MV_OK(0) on success, and return Error Code on failure.

The following sample code is for reference only.

#include <stdio.h>

#include <process.h>
#include <conio.h>
#include "MvCameraControl.h"

//Wait for key input
void WaitForKeyPress(void)
{
    while(!_kbhit())
    {
        Sleep(10);
    }
    _getch();
}
int main()
{
    int nRet = MV_OK;
    void* handle = NULL;
    do 
    {
        //Enumerate device
         MV_CC_DEVICE_INFO_LIST stDeviceList;
        memset(&stDeviceList, 0, sizeof(MV_CC_DEVICE_INFO_LIST));
        nRet = MV_CC_EnumDevices(MV_GIGE_DEVICE | MV_USB_DEVICE, &stDeviceList);
        if (MV_OK != nRet)
        {
            printf("Enum Devices fail! nRet [0x%x]\n", nRet);
            break;
        }
        if (m_stDevList.nDeviceNum == 0)
        {
            printf("no camera found!\n");
            return 0;
        }

        //Select device and create handle
          nRet = MV_CC_CreateHandle(&handle, stDeviceList.pDeviceInfo[0]);
        if (MV_OK != nRet)
        {
            printf("Create Handle fail! nRet [0x%x]\n", nRet);
            break;
        }

        //Open device
          nRet = MV_CC_OpenDevice(handle);
        if (MV_OK != nRet)
        {
            printf("Open Device fail! nRet [0x%x]\n", nRet);
            break;
        }
        bool bIsConnect = MV_CC_IsDeviceConnected(handle);
        if (!bIsConnect)
        {
            printf("Device is connected!\n");
            break;
        }
        else
        {
            printf("Device is unconnected!\n");
            break;
        }
    } while (0);
    if (nRet != MV_OK)
    {
        if (handle != NULL)
        {
         MV_CC_DestroyHandle(handle);
         handle = NULL;
        }
    }
    printf("Press a key to exit.\n");
    WaitForKeyPress();
    return 0;
}

MV_CC_IsDeviceConnected

Check if device is connected.

API Definition

bool MV_CC_IsDeviceConnected(
  void        *handle
);

Parameters

handle

[IN] Device handle, which is returned by MV_CC_CreateHandle or MV_CC_CreateHandleWithoutLog.

Return Value

Return MV_OK(0) on success, and return Error Code on failure.

The following sample code is for reference only.

#include <stdio.h>

#include <process.h>
#include <conio.h>
#include "MvCameraControl.h"

//Wait for key input
void WaitForKeyPress(void)
{
    while(!_kbhit())
    {
        Sleep(10);
    }
    _getch();
}
int main()
{
    int nRet = MV_OK;
    void* handle = NULL;
    do 
    {
        //Enumerate device
         MV_CC_DEVICE_INFO_LIST stDeviceList;
        memset(&stDeviceList, 0, sizeof(MV_CC_DEVICE_INFO_LIST));
        nRet = MV_CC_EnumDevices(MV_GIGE_DEVICE | MV_USB_DEVICE, &stDeviceList);
        if (MV_OK != nRet)
        {
            printf("Enum Devices fail! nRet [0x%x]\n", nRet);
            break;
        }
        if (m_stDevList.nDeviceNum == 0)
        {
            printf("no camera found!\n");
            return 0;
        }

        //Select device and create handle
          nRet = MV_CC_CreateHandle(&handle, stDeviceList.pDeviceInfo[0]);
        if (MV_OK != nRet)
        {
            printf("Create Handle fail! nRet [0x%x]\n", nRet);
            break;
        }

        //Open device
          nRet = MV_CC_OpenDevice(handle);
        if (MV_OK != nRet)
        {
            printf("Open Device fail! nRet [0x%x]\n", nRet);
            break;
        }
        bool bIsConnect = MV_CC_IsDeviceConnected(handle);
        if (!bIsConnect)
        {
            printf("Device is connected!\n");
            break;
        }
        else
        {
            printf("Device is unconnected!\n");
            break;
        }
    } while (0);
    if (nRet != MV_OK)
    {
        if (handle != NULL)
        {
         MV_CC_DestroyHandle(handle);
         handle = NULL;
        }
    }
    printf("Press a key to exit.\n");
    WaitForKeyPress();
    return 0;
}